import http from "@/api";
import {Result, ResultData} from "@/api/interface";
import {CodeGeneration} from "@/api/interface/code-generation";
import {PageParam} from "@/api/interface/common";

// 分页响应参数
type ResultPage = {
    // 列表数据
    records: Array<any>;
    //当前页数
    pageNumber?: number;
    // 每页显示条目个数
    pageSize?: number;
    // 总条目数
    totalRow: number;
}

export default {
  /**
   * 数据库连接
   * @param params
   */
  databaseConnection(params: CodeGeneration.DatabaseParam) {
    return http.post<Result>(`/generator/databaseConnection`, params, {noLoading: true});
  },

  /**
   * 获取数据库所有表名称
   * @param params
   */
  getTableNameList(params: CodeGeneration.DatabaseParam) {
    return http.post<ResultData<string[]>>(`/generator/getTableNameList`, params, {noLoading: true});
  },

  /**
   * 代码生成
   * @param params
   */
  codeGeneration(params: CodeGeneration.CodeGenerationParam) {
    return http.post<string>(`/generator/codeGeneration`, params, {noLoading: true});
  },

  /**
   * 下载生成的代码
   * @param params fileUrl 文件路径
   */
  downloadCode(params: CodeGeneration.downloadCodeParam) {
    return http.downloadGet(`/generator/downloadCode`, params, {noLoading: true});
  },

  /**
   * 分页查询代码生成记录
   * @param params
   */
  queryGenerationLog(params: PageParam) {
    return http.post<ResultPage>(`/generator/queryGenerationLog`, params, {noLoading: true})
  }
}
